/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haiberg.osgi.bundle.helloservice.impl;

import com.haiberg.osgi.bundle.helloservice.HelloService;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;

/**
 *
 * @author gyue
 */
public class HelloServiceFactory implements ServiceFactory<HelloService>{

    private int usageCounter = 0;
    @Override
    public HelloService getService(Bundle bundle, ServiceRegistration<HelloService> sr) {
        usageCounter++;
        HelloService helloService = new HelloServiceImpl();
        return helloService;
    }

    @Override
    public void ungetService(Bundle bundle, ServiceRegistration<HelloService> sr, HelloService s) {
        usageCounter--;
        System.out.println("Number of bundles using service " + usageCounter);
    }
    
}
